package pers.books.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import pers.books.entity.Author;
import pers.books.service.AuthorService;
import pers.books.util.ResultMessage;

/**
 * 
 * AuthorController
 *
 * @author 姜治昊
 * @time 2018年5月5日 下午9:48:11
 */
@RestController
@RequestMapping("author")
public class AuthorController {
	
	@Autowired
	private AuthorService authorService;
	
	@RequestMapping(value="getAuthorById", method=RequestMethod.POST)
	public ResultMessage<Author> getAuthorById(String id) {
		return authorService.getAuthorById(id);
	}
	
	/**
	 * 模糊查询作者
	 * @param nameLike
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping(value="getauthors", method=RequestMethod.POST)
	public Map<String, Object> getAuthors(
			  @RequestParam(value="name", required=false, defaultValue="")String name
			, @RequestParam(value="nationality", required=false, defaultValue="") String nationality
			, int limit, int offset) {
		return authorService.getAuthors("%"+name+"%", "%"+nationality+"%", limit, offset);
	}
	
	/**
	 * 模糊查询作者（用于下拉框数据源）
	 * @param nameLike
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping(value="getall", method=RequestMethod.POST)
	public ResultMessage<?> getAllAuthors(
			  @RequestParam(value="name", required=false, defaultValue="")String name
			, int page, int rows) {
		return authorService.getAllAuthors(name, page, rows);
	}

}
